package com.example.it_com.common;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
//        // 对 /user/login 路径的 CORS 配置
//        registry.addMapping("/user/login")
//                .allowedOrigins("http://localhost:8080", "http://localhost:8081") // 替换为前端域名
//                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
//                .allowedHeaders("*")
//                .allowCredentials(true);

        // 全局 CORS 配置
        registry.addMapping("/**")
                .allowedOrigins("http://localhost:8080", "http://localhost:8081") // 替换为前端域名
                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
                .allowedHeaders("Content-Type", "Authorization")
                .allowCredentials(true);
    }
}

